
component output="false" extends="AbsService" accessors="true" {

	// Delegate
	property name="RoleDelegate" type="it.millemultimedia.easyBlog.delegate.RoleDelegate";

	public it.millemultimedia.easyBlog.service.RoleService function init(){
		
		return this;
	}
	
	public it.millemultimedia.easyBlog.validator.RoleValidator function getValidator(){
		
		return getRoleDelegate().getValidator();
	}
	
	public it.millemultimedia.easyBlog.model.Role function new(){
		
		return getRoleDelegate().createInstance();
	}
	
	public it.millemultimedia.easyBlog.model.Role function getRole( required Any Role ){
		
		return getRoleDelegate().read( arguments.Role, false );
	}
	
	public it.millemultimedia.easyBlog.model.Role[] function getRoles( required Any Role ){
		
		return getRoleDelegate().list( arguments.Role );
	}
	
	public boolean function roleExists( required Any Role ){
		var result = getRoleDelegate().list( arguments.Role );
		
		return arrayLen( result ) gt 0;
	}
	
	public void function saveRole( required Any Role ){
	
		transaction{
		
			try{
				
				
				if( arguments.Role.getidRole()  eq 0 ){
				
					this.createRole( arguments.Role );
				
				}else if( arguments.Role.getIdRole() gt 0 ){
				
					this.updateRole( arguments.Role );
				
				}else{
				
					throw( message="Role id property have undefined value." );
				
				}
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function createRole( required Any Role ){
	
		transaction{
		
			try{
			
				getRoleDelegate().create( arguments.Role );
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function updateRole( required Any Role ){
	
		transaction{
		
			try{
			
				getRoleDelegate().update( arguments.Role );
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function deleteRole( required Any Role ){
	
		transaction{
		
			try{
			
				getRoleDelegate().delete( arguments.Role );
				
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
							
			}
			
		}
		
	}
	
}
